import axios from 'axios'
import ElementUI from "element-ui";
const base = '/api/isv/';

// get请求公共的方法
function getPubfun(url, params = '') {
  return new Promise((resolve) => {
    let obj = {
      arguments: '',
      errorCode: '',
      errorMsg: '',
      result: [],
      success: false,
    }
    axios.get(`${base}${url}${params}`).then(res => {
      if (res.data.success) {
        obj = res.data;
      } else {
        obj.errorMsg = res.data.errorMsg || '服务器出小差了',
          ElementUI.Message({
            message: obj.errorMsg,
            type: 'warning'
          });
      }
      resolve(obj);
    }, err => {
      obj.errorMsg = '网络异常';
      ElementUI.Message({
        message: obj.errorMsg,
        type: 'error'
      });
      resolve(obj);
    });
  });
}

// post请求公共的方法
function postPubfun(url, params = {}) {
  return new Promise((resolve) => {
    let obj = {
      arguments: '',
      errorCode: '',
      errorMsg: '',
      result: [],
      success: false,
    }
    axios.post(`${base}${url}`, params).then(res => {
      if (res.data.success) {
        obj = res.data;
      } else {
        obj.errorMsg = res.data.errorMsg || '服务器出小差了',
          ElementUI.Message({
            message: obj.errorMsg,
            type: 'warning'
          });
      }
      resolve(obj);
    }, err => {
      obj.errorMsg = '网络异常';
      ElementUI.Message({
        message: obj.errorMsg,
        type: 'error'
      });
      resolve(obj);
    });
  });
}


// 获取活动id
export async function getActivityId(params) {
  let data = await getPubfun('activity/queryAll', params);
  return new Promise((resolve) => {
    resolve({
      data
    });
  });
}

// 导出数据
export const exportTicketExcel = (params, reposeType) => {
  return axios.get(`${base}/eportTicket/exportTicketExcel`, params, reposeType)
};

// 查询全部页面数据
export async function queryTicketListByData(params) {
  let data = await postPubfun('ticket/queryTicketListByData', params);
  return new Promise((resolve) => {
    resolve({
      data
    });
  });
}


// 作废门票
export async function delTicketByTicketId(params) {
  let data = await postPubfun('ticket/delTicketByTicketId', params);
  return new Promise((resolve) => {
    resolve({
      data
    });
  });
}


// 根据orderid查询
export async function queryOrderByOrderId(params) {
  let data = await postPubfun('ticket/queryOrderByOrderId', params);
  return new Promise((resolve) => {
    resolve({
      data
    });
  });
}

//  PC_根据订单主键_查询门票列表.
export async function queryTicketListByOrderId(params) {
  let data = await postPubfun('ticket/queryTicketListByOrderId', params);
  return new Promise((resolve) => {
    resolve({
      data
    });
  });
}

//   PC_发起赠票：团体_合作伙伴_赠票
export async function sendTicketByData(params) {
  let data = await postPubfun('ticket/sendTicketByData', params);
  return new Promise((resolve) => {
    resolve({
      data
    });
  });
}

// 个人票
export async function sendTicketByDataPerSon(params) {
  let data = await postPubfun('ticket/sendTicketByPersonal', params);
  return new Promise((resolve) => {
    resolve({
      data
    });
  });
}


// PC_票类型列表_查询所有被启用的
export async function queryTicketTypeListByEnable(params) {
  let data = await postPubfun('ticket/queryTicketTypeListByEnable', params);
  return new Promise((resolve) => {
    resolve({
      data
    });
  });
}

// 审核通过不通过
export async function approveTicketById(params) {
  let data = await postPubfun('ticket/approveTicketById', params);
  return new Promise((resolve) => {
    resolve({
      data
    });
  });
}
// 获取错误日志数据
export async function queryPaginationErrorImportLogs(params) {
  let data = await postPubfun('ticket/import/queryPaginationErrorImportLogs', params);
  return new Promise((resolve) => {
    resolve({
      data
    });
  });
}
// 获取操作日志数据
export async function queryPaginationIsvOperationLogs(params) {
  let data = await postPubfun('ticket/operation/queryPaginationIsvOperationLogs', params);
  return new Promise((resolve) => {
    resolve({
      data
    });
  });
}
